<template>
    <div v-show="$route.path === '/movie'">
        <van-nav-bar title="电影" @click-left="onClick">
            <template #left>
                {{ $store.state.city.name }}&nbsp;&nbsp;<img
                    src=""
                    alt="" style="width: 6px; height: 3px;">
            </template>
        </van-nav-bar>
    </div>
</template>

<script>
import Vue from 'vue';
import { Tab, Tabs } from 'vant';

Vue.use(Tab);
Vue.use(Tabs);
export default {
    created() {
        console.log(this.$route.path);
    },
    mounted() {
        window.addEventListener('scroll', this.handleScroll);
    },
    data() {
        return {

        }
    },
    methods: {
        onClick() {
            this.$router.push({ path: '/city' })
        },
        getScroll() {
            return {
                left: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
                top: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
            };
        },
        handleScroll() {
            if (this.$route.path === '/movie' || this.$route.path === '/cinema') {
                const scrollTop = this.getScroll().top;
                if (scrollTop >= 200) {
                    document.querySelector('.van-nav-bar').style.position = 'fixed';
                    document.querySelector('.van-nav-bar').style.top = '0';
                } else {
                    document.querySelector('.van-nav-bar').style.position = 'static';
                }
            }
        }
    }
}
</script>

<style>
.van-nav-bar {
    width: 100%;
}
</style>
